package net.ojbk.saishi.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;

import net.ojbk.saishi.service.StatisticsService;

/**
 * Servlet implementation class StatisticsServlet
 */
@WebServlet("/StatisticsServlet")
public class StatisticsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public StatisticsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 不需要身份验证
		// matchId
		response.setContentType("text/html;charset=utf-8");
	    response.setCharacterEncoding("utf-8");
	    PrintWriter out = response.getWriter();
	    
	    String matchId=request.getParameter("matchId");   //获取matchId
	    String dayListName[]=StatisticsService.getDayListName();   //获取时间段横坐标
	    String gradeListName[] = StatisticsService.getGradeListName();   //获取年级横坐标
	    
	    int gradeListInfo[] = StatisticsService.getGradeListInfo();     //获取年级提交纵坐标数量
	    int dayListInfo[] = StatisticsService.getDayListInfo();         //获取时间段纵坐标数量
	    
	    int collegeListInfo[] = StatisticsService.getCollegeListInfo();  //获取学院提交数据  需要拆分
	    
	    
	    Map<String,Object>map=new HashMap<String,Object>();    //将数据写入map
		map.put("dayListName", dayListName);
		map.put("gradeListName", gradeListName);
		map.put("gradeListInfo", gradeListInfo);
		map.put("dayListInfo", dayListInfo);
		map.put("collegeListInfo1",collegeListInfo[2] );
		map.put("collegeListInfo2",collegeListInfo[1] );
		map.put("collegeListInfo3",collegeListInfo[0] );
		
		System.out.println(collegeListInfo[2]);
		
		JSONObject json=new JSONObject(map);
		String jsonString=json.toString();
		out.write(json.toString());
		out.flush();
		System.out.println(json.toString());
	    
		
	}

}
